﻿using System;
using System.Collections;
using System.Collections.Generic;
using LitJson;
using UnityEngine;

public class LoginRequest : BaseRequest
{

	private LoginPanel _loginPanel;
	
	protected override void Awake()
	{
		_controllerType = ControllerType.USER;
		_methodType = MethodType.Login;
		base.Awake();
	}
	
	// Use this for initialization
	void Start ()
	{
		_loginPanel = this.gameObject.GetComponent<LoginPanel>();
	}
	
	// Update is called once per frame
	void Update () {
		
	}

	public override void OnResponse(string data)
	{
		JsonData respJson =  JsonMapper.ToObject(data);
		_loginPanel.handleResponse(respJson);
	}

	public void SendRequest(string phone,string password)
	{
		JsonData jsonData = new JsonData();
		jsonData["phone"] = phone;
		jsonData["password"] = password;
		NettyRequest nettyRequest = new NettyRequest();
		nettyRequest.controllerType = (int) _controllerType;
		nettyRequest.methodType = (int) _methodType;
		nettyRequest.data = jsonData.ToJson();
		byte[] dataBytes = ConverterTool.SerialRequestObj(nettyRequest);
		UnityFacade.Instance.ClientManager.SendMsgToServer(dataBytes);
	}
	
	
}
